using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Shop;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.IO;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_Shop_BuyOrder : Member, IRequiresSessionState
{
	public string OrderTitleName = "";
	public string OrderFormNum = "";
	public int OrderFormID = 0;
	public int m_BuyerID = 0;
	public int m_SalerID = 0;
	public int m_UserID;
	public string m_SalerName = "";
	public string m_BuyerName = "";
	public string m_BuyerEmail = "";
	public decimal m_Invoice_TotalPrice = 0m;
	public bool NeedInvoice = false;
	public bool Invoiced = false;
	public bool IsBuyer = false;
	public bool IsSaler = false;
	public string m_DeliverTypeName = "POST";
	public decimal m_Deliver_TotalPrice = 0m;
	public decimal MoneyReceipt = 0m;
	public decimal MoneyTotal = 0m;
	public decimal MoneyGoods = 0m;
	public decimal StandPrice = 0m;
	public int ProductID = 0;
	public int IntPayStatus = 0;
	private DataTable DTOrder;
	private DataTable DTOrderItem;
	public string m_productType = "";
	public string m_orderStatus = "";
	public string m_DeliverStatus = "";
	private Shop_OrderItem objShop_OrderItem = null;
	private Shop_Order _order = null;
	private bool ownerpower = false;
	protected ScriptManager sm;
	protected Literal TxtOrderFormNum;
	protected LinkButton LbtBuyer;
	protected LinkButton LbtSaler;
	protected Literal Order_InputTime;
	protected CheckBox CheckNeedInvoice;
	protected CheckBox CheckInvoied;
	protected Literal OrderStatus;
	protected Literal PayStatus;
	protected Literal DeliverStatus;
	protected Literal InvoiceType;
	protected Literal Contacter_Name;
	protected Literal Contacter_Phone;
	protected Literal Contacter_Address;
	protected Literal Contacter_ZipCode;
	protected Literal Contacter_Email;
	protected Literal Contacter_Mobile;
	protected Literal Need_Invoiced;
	protected Literal Deliver_ChargePaymentType;
	protected Literal lbPayName;
	protected Literal Order_Remark;
	protected Literal ltrListTitle1;
	protected Literal ltrListTitle2;
	protected Panel pnlRptHead;
	protected Repeater Repeater1;
	protected Literal LabTotalPrice;
	protected Literal LabDeliver_TotalPrice;
	protected Literal LabInvoice_TotalPrice;
	protected Literal LabMoneyGoods;
	protected Literal CountMoneyTotal;
	protected Literal ltrCoupon;
	protected Literal LabMoneyTotal;
	protected Literal Pd_ReceiveMoney;
	protected Literal Pd_OwnMoney;
	protected UpdatePanel UpdatePanel1;
	protected Label lblNumber;
	protected Label lblProductName;
	protected Label lblQuantity;
	protected Label lblStandPrice;
	protected Label lblPrice;
	protected TextBox txtEditPrice;
	protected TextBox txtExplain;
	protected HiddenField hfEditItemID;
	protected HiddenField hfEditPrice;
	protected HiddenField hfEditExplain;
	protected Button btnEditPrice;
	protected HtmlGenericControl divEditPrice;
	protected UpdatePanel UpdatePanel2;
	protected Button Pay_Money;
	protected Button ButReturn;
	protected Button ButCusReceive;
	protected PlaceHolder BuyerControl;
	protected Button ButConfirm;
	protected Button Butdel;
	protected Button Re_Money;
	protected Button ButAgreedReturn;
	protected Button ButOpenInvoice;
	protected Button ButSend;
	protected PlaceHolder SalerControl;
	protected HtmlInputHidden lblTime;
	protected HtmlInputHidden Hidden1;
	protected Literal LilSaler;
	protected Literal LilSalers;
	protected HtmlGenericControl Jiaoyidiv;
	protected CheckBox CheckSendMobileMesToCus;
	protected CheckBox CheckSendMesMesToCus;
	protected CheckBox CheckSendEmailMesToCus;
	protected Button ConfirmButton;
	protected Repeater PayInfo;
	protected Repeater InvoiceItem;
	protected Repeater DeliverItem;
	public Shop_OrderItem ObjShop_OrderItem
	{
		get
		{
			if (this.objShop_OrderItem == null)
			{
				this.objShop_OrderItem = new Shop_OrderItem(this.conn);
			}
			return this.objShop_OrderItem;
		}
	}
	public Shop_Order ObjShop_Order
	{
		get
		{
			if (this._order == null)
			{
				this._order = new Shop_Order(this.conn);
			}
			return this._order;
		}
	}
	public bool Ownerpower
	{
		get
		{
			if (base.OwnerStockPower(this.m_SalerID))
			{
				this.ownerpower = true;
			}
			return this.ownerpower;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.OrderFormNum = Fetch.Get("OrderFormNum");
		if (this.OrderFormNum == string.Empty)
		{
			this.WriteErrMsg("", Language.Get("Common/NotData"), "");
		}
		this.DTOrder = this.ObjShop_Order.GetOrderByOrderFormNum(this.OrderFormNum);
		if (this.DTOrder.Rows.Count <= 0)
		{
			this.WriteErrMsg("", Language.Get("Common/NotData"), "");
		}
		this.DTOrderItem = this.ObjShop_OrderItem.GetByOrderNum(this.OrderFormNum);
		DataTable dataTable = this.conn.GetDataTable("select MoneyTrue from HLShop_PayInfo where (Status='pay' or Status='NotPaySaler') and OrderFormNum='" + this.OrderFormNum + "'");
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			for (int i = 0; i < dataTable.Rows.Count; i++)
			{
				if (dataTable.Rows[i]["MoneyTrue"] != null)
				{
					this.MoneyReceipt += decimal.Parse(dataTable.Rows[i]["MoneyTrue"].ToString());
				}
			}
		}
		dataTable.Dispose();
		this.m_UserID = base.user.UserID;
		this.m_BuyerID = Convert.ToInt32(this.DTOrder.Rows[0]["UserID"]);
		this.m_SalerID = Convert.ToInt32(this.DTOrder.Rows[0]["SalerID"]);
		this.m_SalerName = this.DTOrder.Rows[0]["SalerName"].ToString();
		this.m_BuyerName = this.DTOrder.Rows[0]["BuyerName"].ToString();
		this.m_BuyerEmail = this.DTOrder.Rows[0]["Email"].ToString();
		this.OrderFormID = Convert.ToInt32(this.DTOrder.Rows[0]["OrderFormID"]);
		this.MoneyGoods = Text.ToDecimal(this.DTOrder.Rows[0]["MoneyGoods"].ToString());
		this.MoneyTotal = Text.ToDecimal(this.DTOrder.Rows[0]["MoneyTotal"].ToString());
		this.m_Invoice_TotalPrice = Text.ToDecimal(this.DTOrder.Rows[0]["InvoiceRate"].ToString());
		this.NeedInvoice = Convert.ToBoolean(this.DTOrder.Rows[0]["NeedInvoice"]);
		if (Convert.ToInt32(this.DTOrder.Rows[0]["Invoiced"]) == 0)
		{
			this.Invoiced = false;
		}
		else
		{
			this.Invoiced = true;
		}
		this.m_Deliver_TotalPrice = Text.ToDecimal(this.DTOrder.Rows[0]["Deliver_TotalPrice"].ToString());
		this.m_DeliverTypeName = this.DTOrder.Rows[0]["DeliverTypeName"].ToString();
		this.m_productType = this.DTOrder.Rows[0]["TradeType"].ToString();
		this.m_orderStatus = this.DTOrder.Rows[0]["Status"].ToString();
		this.m_DeliverStatus = this.DTOrder.Rows[0]["DeliverStatus"].ToString();
		this.IntPayStatus = Convert.ToInt32(this.DTOrder.Rows[0]["PayStatus"].ToString());
		ShopConfigBll shopConfigBll = new ShopConfigBll();
		DataTable config = shopConfigBll.GetConfig();
		int num = 1;
		try
		{
			num = Convert.ToInt32(config.Rows[0]["FahuoTiem"]);
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[]
			{
				"正常操作"
			});
			num = 0;
		}
		if (this.DTOrder.Rows[0]["PayStatus"].ToString().Equals("0") || this.m_DeliverStatus != "0" || this.DTOrder.Rows[0]["SelectedPayType"].ToString() != "0")
		{
			num = 0;
		}
		this.Hidden1.Value = num.ToString();
		DateTime dateTime = Convert.ToDateTime(this.DTOrder.Rows[0]["UpdateTime"]).AddDays((double)(num + 1));
		this.lblTime.Value = dateTime.ToShortDateString();
		object scalar = this.conn.GetScalar("Select StandPrice From [HLShop_Product] Where ProductID=" + this.DTOrderItem.Rows[0]["ProductID"], new IDbDataParameter[0]);
		this.StandPrice = Convert.ToDecimal(scalar);
		if (this.m_UserID == this.m_BuyerID)
		{
			this.IsBuyer = true;
			this.BuyerControl.Visible = true;
			this.SalerControl.Visible = false;
			this.ButReturn.Visible = false;
			this.ButCusReceive.Visible = false;
			if (int.Parse(this.m_DeliverStatus) == 1)
			{
				this.ButCusReceive.Visible = true;
				this.ButReturn.Visible = true;
			}
			DataSet dataSet = this.conn.GetDataSet("select * from HLShop_DeliverItem where OrderID=" + this.OrderFormID);
			if (dataSet.Tables[0].Rows.Count > 0 && dataSet != null)
			{
				if (int.Parse(this.m_DeliverStatus) == 2 && bool.Parse(dataSet.Tables[0].Rows[0]["Received"].ToString()))
				{
					this.ButCusReceive.Visible = false;
				}
			}
			else
			{
				if (int.Parse(this.m_orderStatus) == 0)
				{
					this.ButCusReceive.Visible = false;
				}
			}
		}
		else
		{
			if (this.m_UserID == this.m_SalerID)
			{
				this.IsSaler = true;
				this.BuyerControl.Visible = false;
				this.SalerControl.Visible = true;
				if (this.m_DeliverStatus == "4")
				{
					this.ButConfirm.Visible = false;
				}
				if (int.Parse(this.m_orderStatus) >= 1)
				{
					this.ButConfirm.Visible = false;
				}
				if (this.m_DeliverStatus == "-1")
				{
					this.ButSend.Visible = false;
					this.ButAgreedReturn.Visible = true;
				}
				else
				{
					if (this.m_DeliverStatus == "-2")
					{
						this.ButAgreedReturn.Visible = false;
						this.ButSend.Visible = false;
					}
					else
					{
						this.ButAgreedReturn.Visible = false;
						this.ButSend.Visible = true;
					}
				}
				DataSet dataSet2 = this.conn.GetDataSet("select * from HLShop_PayInfo where OrderFormNum='" + this.OrderFormNum + "'");
				if (dataSet2 == null && dataSet2.Tables.Count == 0 && string.IsNullOrEmpty(dataSet2.ToString()))
				{
					if (dataSet2.Tables[0].Rows[0]["Status"].ToString() == "Pay")
					{
						this.Re_Money.Visible = false;
					}
				}
				if (int.Parse(this.m_DeliverStatus) == 2 || int.Parse(this.DTOrder.Rows[0]["Invoiced"].ToString()) == 1)
				{
					this.ButOpenInvoice.Visible = false;
				}
				if (this.m_orderStatus == "0")
				{
					if (this.DTOrder.Rows[0]["PayStatus"].ToString() != "0")
					{
						this.Butdel.Visible = false;
					}
				}
				if (int.Parse(this.m_orderStatus) >= 1)
				{
					this.Butdel.Visible = false;
				}
				if (this.DTOrder.Rows[0]["PayStatus"].ToString() == "1" && this.m_orderStatus == "2")
				{
					this.Re_Money.Visible = false;
				}
				if (Convert.ToInt32(this.DTOrder.Rows[0]["SelectedPayType"]) == 0)
				{
					this.Re_Money.Visible = false;
				}
				if (this.m_DeliverStatus == "1")
				{
					this.ButSend.Visible = false;
				}
				else
				{
					if (this.m_DeliverStatus == "2")
					{
						this.ButConfirm.Visible = false;
						this.Butdel.Visible = false;
						this.Re_Money.Visible = false;
						this.ButOpenInvoice.Visible = false;
						this.ButSend.Visible = false;
					}
				}
			}
		}
		if (!this.IsBuyer && !this.IsSaler)
		{
			this.WriteErrMsg("", Language.Get("Common/NotData"), "");
		}
		if (!base.IsPostBack)
		{
			this.InitPage();
			this.BindPayInfo();
			this.BindInvoiceItem();
			this.BindDeliverItem();
			if (decimal.Parse(this.Pd_OwnMoney.Text) == 0m || !this.JustAuction(this.OrderFormNum, int.Parse(this.m_productType)))
			{
				this.Pay_Money.Visible = false;
			}
			if (this.IntPayStatus < 1)
			{
				this.CkeckSalerIsLocked();
			}
		}
	}
	public string PayOutStatus(string Strpay)
	{
		string result;
		if (Strpay.ToLower() == "pay" || Strpay == "pay")
		{
			result = "支付完成";
		}
		else
		{
			if (Strpay.ToLower() == "notpaysaler")
			{
				result = "支付到平台";
			}
			else
			{
				result = "未支付成功";
			}
		}
		return result;
	}
	private void CkeckSalerIsLocked()
	{
		int num = this.conn.ExecuteCount("select count(*) from  [HL_User]  where IsLocked=1 and UserID=" + this.m_SalerID.ToString());
		if (num > 0)
		{
			this.LbtSaler.Enabled = false;
			this.BuyerControl.Visible = false;
			this.SalerControl.Visible = false;
			this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('卖家账号被锁定，必须经过解锁才能正常交易！');</script>");
		}
		num = this.conn.ExecuteCount("select count(*) from  [HL_User]  where IsLocked=1 and UserID=" + this.m_BuyerID.ToString());
		if (num > 0)
		{
			base.Response.Redirect("~/Passport/Login.aspx");
		}
		int shopID = this.GetShopID(this.m_BuyerID);
		if (shopID < 1)
		{
			this.LbtBuyer.Enabled = false;
		}
		shopID = this.GetShopID(this.m_SalerID);
		if (shopID < 1)
		{
			this.LbtSaler.Enabled = false;
		}
	}
	public bool JustAuction(string OrderFormNum, int TradeType)
	{
		bool result;
		if (TradeType == 2)
		{
			DataTable dataTable = this.conn.GetDataTable("select * from HLShop_Order where TradeType=2 and DateDiff(s,UpdateTime,getdate())>=0 and OrderFormNum='" + OrderFormNum + "'");
			result = (dataTable != null && dataTable.Rows.Count > 0);
		}
		else
		{
			result = true;
		}
		return result;
	}
	protected void BindPayInfo()
	{
		DataTable dataTable = this.conn.GetDataTable("select * from HLShop_PayInfo where OrderFormNum='" + this.OrderFormNum + "' order by PayTime Desc");
		if (dataTable.Rows.Count > 0)
		{
			this.PayInfo.DataSource = dataTable;
			this.PayInfo.DataBind();
		}
	}
	protected void BindInvoiceItem()
	{
		Shop_InvoiceItem shop_InvoiceItem = new Shop_InvoiceItem(this.conn);
		DataTable invoiceByOrderFormID = shop_InvoiceItem.GetInvoiceByOrderFormID(this.OrderFormID);
		if (invoiceByOrderFormID.Rows.Count > 0)
		{
			this.InvoiceItem.DataSource = invoiceByOrderFormID;
			this.InvoiceItem.DataBind();
			this.Need_Invoiced.Text = "有";
		}
		else
		{
			this.Need_Invoiced.Text = "无";
		}
	}
	protected void BindDeliverItem()
	{
		Shop_DeliverItem shop_DeliverItem = new Shop_DeliverItem(this.conn);
		DataTable deliverItemByOrderFormID = shop_DeliverItem.GetDeliverItemByOrderFormID(this.OrderFormID);
		if (deliverItemByOrderFormID.Rows.Count > 0)
		{
			this.DeliverItem.DataSource = deliverItemByOrderFormID;
			this.DeliverItem.DataBind();
		}
	}
	public string ShowFatreturnStatus(string DeliverType)
	{
		string result;
		if (DeliverType == "1")
		{
			result = "已退货";
		}
		else
		{
			result = "已发货";
		}
		return result;
	}
	protected void InitPage()
	{
		decimal d = this.MoneyTotal - this.MoneyReceipt;
		if (d < 0m)
		{
		}
		this.OrderTitleName = TextFormat.GetProductType(this.m_productType);
		this.TxtOrderFormNum.Text = this.OrderFormNum;
		this.LbtBuyer.Text = this.m_BuyerName;
		this.LbtSaler.Text = this.m_SalerName;
		this.Order_InputTime.Text = this.DTOrder.Rows[0]["InputTime"].ToString();
		this.CheckInvoied.Checked = this.Invoiced;
		for (int i = 0; i < this.DTOrderItem.Rows.Count; i++)
		{
			if (int.Parse(this.DTOrderItem.Rows[i]["NeedInvoice"].ToString()) == 1)
			{
				this.CheckNeedInvoice.Checked = true;
				break;
			}
		}
		DataSet dataSet = this.conn.GetDataSet("select * from HLShop_InvoiceItem where OrderFormID=" + this.OrderFormID);
		if (dataSet != null && !string.IsNullOrEmpty(dataSet.ToString()) && dataSet.Tables[0].Rows.Count > 0)
		{
			int num = int.Parse(dataSet.Tables[0].Rows[0]["InvoiceType"].ToString());
			if (num == 0)
			{
				this.InvoiceType.Text = "地税普通发票";
			}
			else
			{
				if (num == 1)
				{
					this.InvoiceType.Text = "国税普通发票";
				}
				else
				{
					if (num == 2)
					{
						this.InvoiceType.Text = "增值税发票";
					}
					else
					{
						this.InvoiceType.Text = "暂无";
					}
				}
			}
		}
		else
		{
			this.InvoiceType.Text = "暂无";
		}
		this.OrderStatus.Text = TextFormat.GetOrderStatus(this.m_orderStatus, TextFormat.GetReceived(this.OrderFormID.ToString()));
		this.PayStatus.Text = TextFormat.GetPayStatus(this.DTOrder.Rows[0]["PayStatus"].ToString());
		this.DeliverStatus.Text = TextFormat.GetDeliverStatus(this.m_DeliverStatus);
		this.LilSaler.Text = this.m_SalerName;
		this.LilSalers.Text = this.m_SalerName;
		this.Contacter_Name.Text = this.DTOrder.Rows[0]["ContacterName"].ToString();
		this.Contacter_Phone.Text = this.DTOrder.Rows[0]["Phone"].ToString();
		string str = this.DTOrder.Rows[0]["Province"].ToString();
		string str2 = this.DTOrder.Rows[0]["City"].ToString();
		string str3 = "";
		if (this.DTOrder.Columns.Contains("Area"))
		{
			if (this.DTOrder.Rows[0]["Area"] != DBNull.Value)
			{
				str3 = this.DTOrder.Rows[0]["Area"].ToString();
			}
		}
		string str4 = this.DTOrder.Rows[0]["Address"].ToString();
		this.Contacter_Address.Text = str + str2 + str3 + str4;
		this.Contacter_ZipCode.Text = this.DTOrder.Rows[0]["ZipCode"].ToString();
		this.Contacter_Email.Text = this.DTOrder.Rows[0]["Email"].ToString();
		this.Contacter_Mobile.Text = this.DTOrder.Rows[0]["Mobile"].ToString();
		this.Order_Remark.Text = this.DTOrder.Rows[0]["Remark"].ToString();
		if (this.Order_Remark.Text.Equals("/"))
		{
			this.Order_Remark.Text = "无备注";
		}
		this.Need_Invoiced.Text = this.DTOrder.Rows[0]["InvoiceContent"].ToString();
		string text = this.DTOrder.Rows[0]["DeliverTypeName"].ToString();
		if (string.IsNullOrEmpty(text))
		{
			text = Language.Get("Shop/Deliver/DeliverPayType/Type0");
		}
		this.Deliver_ChargePaymentType.Text = text;
		int num2 = 0;
		try
		{
			num2 = Convert.ToInt32(this.DTOrder.Rows[0]["SelectedPayType"]);
		}
		catch
		{
		}
		if (num2 == 0)
		{
			this.lbPayName.Text = "商城帐户支付";
		}
		else
		{
			Shop_PayType shop_PayType = new Shop_PayType(this.conn);
			DataTable payTypeByUserIDTypeID = shop_PayType.GetPayTypeByUserIDTypeID(Convert.ToInt32(this.DTOrder.Rows[0]["SalerID"]), num2);
			if (payTypeByUserIDTypeID != null)
			{
				if (payTypeByUserIDTypeID.Rows.Count > 0)
				{
					this.lbPayName.Text = payTypeByUserIDTypeID.Rows[0]["TypeName"].ToString();
				}
				payTypeByUserIDTypeID.Dispose();
			}
		}
		this.Repeater1.DataSource = this.DTOrderItem;
		this.Repeater1.DataBind();
		if (this.m_productType == "5")
		{
			this.ltrListTitle2.Text = "换购积分";
			for (int j = 0; j < this.Repeater1.Items.Count; j++)
			{
				Literal literal = (Literal)this.Repeater1.Items[j].FindControl("Pd_ListContent2");
				HiddenField hiddenField = (HiddenField)this.Repeater1.Items[j].FindControl("hfNeedPresentExp");
				if (hiddenField != null)
				{
					if (!string.IsNullOrEmpty(hiddenField.Value))
					{
						literal.Text = hiddenField.Value;
					}
				}
			}
		}
		if (!this.EditPriceCondition())
		{
			this.pnlRptHead.Visible = false;
			for (int j = 0; j < this.Repeater1.Items.Count; j++)
			{
				Panel panel = (Panel)this.Repeater1.Items[j].FindControl("pnlRptItem");
				if (panel != null)
				{
					panel.Visible = false;
				}
			}
		}
		else
		{
			if (!this.Ownerpower)
			{
				this.pnlRptHead.Visible = false;
				for (int j = 0; j < this.Repeater1.Items.Count; j++)
				{
					Panel panel = (Panel)this.Repeater1.Items[j].FindControl("pnlRptItem");
					if (panel != null)
					{
						panel.Visible = false;
					}
				}
			}
		}
		this.Pd_ReceiveMoney.Text = this.MoneyReceipt.ToString();
		if (this.DeliverStatus.Text == "1")
		{
			Shop_DeliverItem shop_DeliverItem = new Shop_DeliverItem(this.conn);
			if (shop_DeliverItem.UpdateReceivedStatusAfterDays(this.OrderFormID, 15))
			{
				OrderAction orderAction = new OrderAction(this.conn);
				orderAction.CusReceive(this.OrderFormID);
				this.DeliverStatus.Text = Language.GetMemberMsg("Order/DeliverStatus2", new string[0]);
			}
		}
		this.OrderMoney();
		this.SetButtonVisible();
	}
	private void OrderMoney()
	{
		string commandText = "Select sum(TotalPrice) From [HLShop_OrderItem] Where OrderFormNum=" + this.OrderFormNum;
		this.LabTotalPrice.Text = Convert.ToString(this.conn.GetScalar(commandText, new IDbDataParameter[0]));
		string text = "0.00";
		string text2 = "0.00";
		string text3 = "0.00";
		string sql = "select SUM(Invoice_TotalPrice) as Invoice_TotalPrice,SUM(Deliver_TotalPrice) as Deliver_TotalPrice,SUM(MoneyGoods) as MoneyGoods from HLShop_Order where OrderFormNum='" + this.OrderFormNum + "'";
		DataTable dataTable = this.conn.GetDataTable(sql);
		if (dataTable.Rows.Count > 0)
		{
			text2 = dataTable.Rows[0]["Deliver_TotalPrice"].ToString();
			text = dataTable.Rows[0]["Invoice_TotalPrice"].ToString();
			text3 = dataTable.Rows[0]["MoneyGoods"].ToString();
		}
		this.LabDeliver_TotalPrice.Text = text2;
		this.LabMoneyGoods.Text = text3;
		decimal num = 0m;
		HoWave.Data.Bll.CouponItem couponItem = new HoWave.Data.Bll.CouponItem();
		if (this.DTOrder.Rows[0]["CouponItemID"] != DBNull.Value)
		{
			int num2 = Convert.ToInt32(this.DTOrder.Rows[0]["CouponItemID"].ToString());
			if (num2 > 0)
			{
				DataTable listByItemID = couponItem.GetListByItemID(num2.ToString());
				if (listByItemID.Rows.Count > 0)
				{
					num = Convert.ToDecimal(listByItemID.Rows[0]["CouponParvalue"].ToString());
					string text4 = listByItemID.Rows[0]["CouponName"].ToString();
					this.ltrCoupon.Text = string.Concat(new object[]
					{
						"使用优惠券为",
						text4,
						"，面值为",
						num,
						"元"
					});
				}
			}
		}
		this.LabInvoice_TotalPrice.Text = text;
		this.CountMoneyTotal.Text = (decimal.Parse(this.LabDeliver_TotalPrice.Text) + decimal.Parse(this.LabInvoice_TotalPrice.Text) + decimal.Parse(this.LabMoneyGoods.Text) - num).ToString();
		this.LabMoneyTotal.Text = this.CountMoneyTotal.Text;
		this.Pd_OwnMoney.Text = ((decimal.Parse(this.LabMoneyTotal.Text) - decimal.Parse(this.Pd_ReceiveMoney.Text) >= 0m) ? (decimal.Parse(this.LabMoneyTotal.Text) - decimal.Parse(this.Pd_ReceiveMoney.Text)) : 0m).ToString();
	}
	public string CountTotalPrice()
	{
		decimal d = 0m;
		for (int i = 0; i < this.Repeater1.Items.Count; i++)
		{
			Literal literal = (Literal)this.Repeater1.Items[i].FindControl("Pd_Total");
			decimal d2 = decimal.Parse(literal.Text.Substring(1, literal.Text.Length));
			d += d2;
		}
		return d.ToString();
	}
	protected void SetButtonVisible()
	{
		if (this.m_productType == "2" || this.m_productType == "3")
		{
			DataTable dataTable = this.conn.GetDataTable("Select Cycle,EndDate,TempSubScriptionRate From HLShop_Product Where ProductID in(Select ProductID From HLShop_OrderItem Where OrderFormID=" + this.OrderFormID + ")");
			if (dataTable.Rows.Count <= 0)
			{
				this.ButReturn.Visible = false;
				this.ButCusReceive.Visible = false;
				this.ButSend.Visible = false;
				this.ButConfirm.Visible = false;
				this.ButOpenInvoice.Visible = false;
				this.Re_Money.Visible = false;
				this.Pay_Money.Visible = false;
				this.WriteErrMsg("", "商品不存在！", "");
			}
			string b = dataTable.Rows[0]["Cycle"].ToString();
			DateTime value = Convert.ToDateTime(dataTable.Rows[0]["EndDate"]);
			if (this.DTOrder.Rows[0]["Cycle"].ToString() == b)
			{
				if (DateTime.Now.CompareTo(value) <= 0)
				{
					this.ButReturn.Visible = false;
					this.ButCusReceive.Visible = false;
					this.ButSend.Visible = false;
					this.ButConfirm.Visible = false;
					this.ButOpenInvoice.Visible = false;
					this.Re_Money.Visible = false;
					if (Convert.ToDecimal(dataTable.Rows[0]["TempSubScriptionRate"]) > 0m)
					{
						this.Pay_Money.Visible = true;
					}
					else
					{
						this.Pay_Money.Visible = false;
					}
				}
			}
		}
		if (this.m_orderStatus == "0")
		{
			this.ButReturn.Visible = false;
			this.ButCusReceive.Visible = false;
			this.ButOpenInvoice.Visible = false;
			this.ButSend.Visible = false;
		}
		else
		{
			if (this.m_orderStatus == "1")
			{
				this.ButConfirm.Visible = false;
				this.Butdel.Visible = false;
			}
		}
		if (Convert.ToDecimal(this.DTOrder.Rows[0]["MoneyReceipt"]) >= Convert.ToDecimal(this.DTOrder.Rows[0]["MoneyTotal"]))
		{
			this.Re_Money.Visible = false;
			this.Pay_Money.Visible = false;
		}
		if (Convert.ToDecimal(this.Pd_OwnMoney.Text) > 0m)
		{
			this.Pay_Money.Visible = true;
		}
		if (this.m_DeliverStatus == "1")
		{
			this.ButSend.Visible = false;
		}
		else
		{
			if (this.m_DeliverStatus == "2")
			{
				this.ButCusReceive.Visible = false;
				this.ButReturn.Visible = false;
				this.ButSend.Visible = false;
			}
			else
			{
				if (this.m_DeliverStatus == "4")
				{
					this.ButConfirm.Visible = false;
					this.ButSend.Visible = false;
				}
				else
				{
					this.ButReturn.Visible = false;
					this.ButCusReceive.Visible = false;
				}
			}
		}
		this.ButOpenInvoice.Visible = true;
	}
	protected void ConfirmButton_Click(object sender, EventArgs e)
	{
		if (this.IsSaler)
		{
			if (this.m_orderStatus.Trim() == "0")
			{
				string userName = base.user.UserName;
				string smtpserver = this.config["MailSmtpServer"].ToString();
				string mailuser = this.config["MailServerUserName"].ToString();
				string mailpassword = this.config["MailServerPassWord"].ToString();
				string mailFrom = this.config["MailServerFrom"].ToString();
				string text = "";
				Shop_Order shop_Order = new Shop_Order(this.conn);
				string text2 = "订单确认通知";
				string text3 = this.config["MessageOfOrderConfirm"].ToString();
				text3 = text3.Replace("{$UserName$}", this.m_BuyerName);
				text3 = text3.Replace("{$InputTime$}", this.DTOrder.Rows[0]["InputTime"].ToString());
				text3 = text3.Replace("{$OrderFormNum$}", this.OrderFormNum);
				if (shop_Order.updateStatus(this.OrderFormNum, "", "", "1"))
				{
					text += Language.Get("Common/Success");
				}
				if (this.CheckSendMobileMesToCus.Checked)
				{
					string text4 = "";
					if (this.DTOrder.Rows[0]["Mobile"] != null)
					{
						text4 = this.DTOrder.Rows[0]["Mobile"].ToString();
					}
					if (!string.IsNullOrEmpty(text4))
					{
						MobileMessage mobileMessage = new MobileMessage();
						if (mobileMessage.Send(text4, text3, userName))
						{
							text = text + "<br/>" + Language.GetMemberMsg("Order/Notice/MobileSuccess", new string[0]);
						}
					}
				}
				if (this.CheckSendMesMesToCus.Checked)
				{
					MessageBll messageBll = new MessageBll(this.conn);
					if (messageBll.AddMessage(this.m_SalerName, "Users", text2, text3, 0, 0, 1, 0, this.m_BuyerName, "", 1))
					{
						text = text + "<br/>" + Language.GetMemberMsg("Order/Notice/MessageSuccess", new string[0]);
					}
				}
				if (this.CheckSendEmailMesToCus.Checked)
				{
					try
					{
						Email email = new Email();
						email.SendEmail(smtpserver, mailuser, mailpassword, mailFrom, text3, this.m_BuyerEmail, text2);
						text = text + "<br/>" + Language.GetMemberMsg("Order/Notice/EmailSuccess", new string[0]);
					}
					catch
					{
					}
				}
				base.AddInfoItem(this.OrderFormID, "0", this.m_SalerID);
				this.WriteSuccessMsg("", text, "Shop_BuyOrder.aspx?OrderFormNum=" + this.OrderFormNum);
			}
			else
			{
				this.WriteErrMsg("", "订单已确认！", "");
			}
		}
	}
	protected void Butdel_Click(object sender, EventArgs e)
	{
		if (this.m_orderStatus == "1")
		{
			this.WriteErrMsg("", Language.Get("Common/Fail", ""), "");
		}
		else
		{
			if (!this.IsSaler)
			{
				this.WriteErrMsg("", Language.Get("Common/Fail", ""), "");
			}
			else
			{
				Shop_Order shop_Order = new Shop_Order(this.conn);
				if (shop_Order.DeleteOrder(this.OrderFormID.ToString()))
				{
					this.WriteSuccessMsg("", Language.GetMemberMsg("Common/DeleteSuccess", new string[0]), "Shop_ManageOrder.aspx");
				}
				else
				{
					this.WriteErrMsg("", Language.Get("Common/Fail", ""), "");
				}
			}
		}
	}
	protected void ButAgreedReturn_Click(object sender, EventArgs e)
	{
		if (this.OrderFormID > 0)
		{
			if (this.m_productType == "5")
			{
				if (this.DTOrder.Rows[0]["PresentExpTotal"] != null)
				{
					string value = this.DTOrder.Rows[0]["PresentExpTotal"].ToString();
					int num = Convert.ToInt32(value);
					UserExpAction userExpAction = new UserExpAction(this.conn);
					userExpAction.AddUserExpSql(this.m_BuyerID, (long)num, 1, "订单编号" + this.OrderFormNum + "退货商品的积分", "+");
					userExpAction.AddUserExpSql(this.m_SalerID, (long)num, 0, "订单编号" + this.OrderFormNum + "退货商品的积分", "-");
				}
			}
			OrderAction orderAction = new OrderAction(this.conn);
			int num2 = -100;
			if (this.DTOrder.Columns.Contains("SelectedPayType"))
			{
				if (this.DTOrder.Rows[0]["SelectedPayType"] != DBNull.Value)
				{
					num2 = Convert.ToInt32(this.DTOrder.Rows[0]["SelectedPayType"].ToString());
				}
			}
			bool flag = false;
			if (num2 == 0)
			{
				flag = orderAction.ShopBankReturnOrder(this.OrderFormID);
			}
			if (flag)
			{
				this.ReturnGoodsNotice();
			}
		}
	}
	private void ReturnGoodsNotice()
	{
		string title = "同意退货通知";
		string text = this.config["AgreeReturnGoods"].ToString();
		text = text.Replace("{$UserName$}", this.m_BuyerName);
		text = text.Replace("{$InputTime$}", this.DTOrder.Rows[0]["InputTime"].ToString());
		text = text.Replace("{$OrderFormNum$}", this.OrderFormNum);
		MessageBll messageBll = new MessageBll(this.conn);
		if (messageBll.AddMessage(this.m_SalerName, "Users", title, text, 0, 0, 1, 0, this.m_BuyerName, "", 1))
		{
			string msg = "操作成功！<br>" + Language.GetMemberMsg("Order/Notice/MessageSuccess", new string[0]);
			this.WriteSuccessMsg("", msg, "Shop_BuyOrder.aspx?OrderFormNum=" + this.OrderFormNum);
		}
	}
	protected void ButOpenInvoice_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("Shop_AddInvoice.aspx?OrderFormNum=" + this.OrderFormNum + "&ComeUrl=" + this.Page.Request.Url.ToString());
	}
	protected void ButSend_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("Shop_AddOrderSend.aspx?DeliverType=0&OrderFormNum=" + this.OrderFormNum + "&ComeUrl=" + this.Page.Request.Url.ToString());
	}
	protected void PayMoney(object sender, EventArgs e)
	{
		base.Response.Redirect("Shop_PayOrder.aspx?OrderFormNum=" + this.OrderFormNum);
	}
	protected void ButReturn_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("Shop_AddOrderSend.aspx?DeliverType=1&OrderFormNum=" + this.OrderFormNum + "&ComeUrl=" + this.Page.Request.Url.ToString());
	}
	protected void ButCusReceive_Click(object sender, EventArgs e)
	{
		OrderAction orderAction = new OrderAction(this.conn);
		if (orderAction.CusReceive(this.OrderFormID))
		{
			this.WriteSuccessMsg("", Language.Get("Common/Success"), "Shop_BuyOrder.aspx?OrderFormNum=" + this.OrderFormNum);
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/Fail", ""), "");
		}
	}
	private void EditInfoItem()
	{
		if (this.OrderFormID > 0)
		{
			Shop_Order shop_Order = new Shop_Order();
			DataTable orderAreadyByOrderID = shop_Order.GetOrderAreadyByOrderID(this.OrderFormID);
			for (int i = 0; i < orderAreadyByOrderID.Rows.Count; i++)
			{
				string value = "";
				if (orderAreadyByOrderID.Rows[i]["PayTime"] != DBNull.Value)
				{
					value = orderAreadyByOrderID.Rows[i]["PayTime"].IsNull(new object[0]);
				}
				decimal d = 0m;
				if (orderAreadyByOrderID.Rows[i]["MoneyTotal"] != DBNull.Value)
				{
					d = orderAreadyByOrderID.Rows[i]["MoneyTotal"].ToDecimal2();
				}
				decimal num = 0m;
				if (orderAreadyByOrderID.Rows[i]["MoneyReceipt"] != DBNull.Value)
				{
					num = orderAreadyByOrderID.Rows[i]["MoneyReceipt"].ToDecimal2();
				}
				decimal num2 = 0m;
				if (orderAreadyByOrderID.Rows[i]["alMoneyReceipt"] != DBNull.Value)
				{
					decimal d2 = orderAreadyByOrderID.Rows[i]["alMoneyReceipt"].ToDecimal2();
					if (num > d2)
					{
						num2 = num - d2;
					}
				}
				decimal value2 = d + num2;
				DataTable dataTable = BLLInstance.BllStockInfoOrder.GetList("OrderID=" + this.OrderFormID).Tables[0];
				for (int j = 0; j < dataTable.Rows.Count; j++)
				{
					int infoOrderID = dataTable.Rows[j]["InfoOrderID"].ToInt32(new int[0]);
					HoWave.Data.Model.StockInfoOrder model = BLLInstance.BllStockInfoOrder.GetModel(infoOrderID);
					if (model != null)
					{
						model.InfoOrderID = infoOrderID;
						model.Fee = new decimal?(num2);
						if (!string.IsNullOrEmpty(value))
						{
							model.ReceiptDate = new DateTime?(Convert.ToDateTime(value));
						}
						model.ReceiptMoney = new decimal?(value2);
						model.AlreadyReceiptMoney = new decimal?(num);
						BLLInstance.BllStockInfoOrder.Update(model);
					}
				}
			}
		}
	}
	protected void ButUpdate_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("Shop_UpdateOrderByBuy.aspx?OrderFormNum=" + this.OrderFormNum);
	}
	protected void ButReturnMoney_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("Shop_RePayOrder.aspx?OrderFormNum=" + this.OrderFormNum + "&ComeUrl=" + this.Page.Request.Url.ToString());
	}
	public int GetShopID(int UserID)
	{
		int result = 0;
		DataSet dataSet = this.conn.GetDataSet("select * from HLShop_Shop where ShopOwnerID=" + UserID);
		if (dataSet != null && dataSet.Tables[0].Rows.Count > 0)
		{
			result = int.Parse(dataSet.Tables[0].Rows[0]["ShopID"].ToString());
		}
		return result;
	}
	public bool ExeistShop(int ShopID)
	{
		string path = "../Shop/" + ShopID.ToString();
		return Directory.Exists(base.Server.MapPath(path));
	}
	protected void LbtBuyer_Click(object sender, EventArgs e)
	{
		Shop_Product shop_Product = new Shop_Product();
		int shopID = this.GetShopID(this.m_BuyerID);
		if (shopID > 0)
		{
			shop_Product.Redirect("../Store/ShopIndex.aspx?ShopID=" + shopID.ToString(), "_blank", string.Empty);
		}
		else
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('该店铺不存在!');</script>");
		}
	}
	protected void LbtSaler_Click(object sender, EventArgs e)
	{
		Shop_Product shop_Product = new Shop_Product();
		int shopID = this.GetShopID(this.m_SalerID);
		if (shopID > 0)
		{
			shop_Product.Redirect("../Store/ShopIndex.aspx?ShopID=" + shopID.ToString(), "_blank", string.Empty);
		}
		else
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('该店铺不存在!');</script>");
		}
	}
	protected void btnEditPrice_Click(object sender, EventArgs e)
	{
		CreateOrder createOrder = new CreateOrder(this.conn);
		if (this.EditPriceCondition())
		{
			int orderItemID = 0;
			if (!string.IsNullOrEmpty(this.hfEditItemID.Value))
			{
				orderItemID = Convert.ToInt32(this.hfEditItemID.Value);
			}
			decimal editPrice = 0m;
			if (!string.IsNullOrEmpty(this.txtEditPrice.Text))
			{
				editPrice = Convert.ToDecimal(this.txtEditPrice.Text);
			}
			string text = this.txtExplain.Text;
			createOrder.SalerID = this.m_SalerID;
			createOrder.SalerName = this.m_SalerName;
			int num = createOrder.EditOrderItemPrice(orderItemID, editPrice, text);
			if (num > 0)
			{
				this.DTOrder = this.ObjShop_Order.GetOrderByOrderFormNum(this.OrderFormNum);
				this.DTOrderItem = this.ObjShop_OrderItem.GetByOrderNum(this.OrderFormNum);
				this.Repeater1.DataSource = this.DTOrderItem;
				this.Repeater1.DataBind();
				this.OrderMoney();
				this.divEditPrice.Style["display"] = "none";
			}
		}
	}
	private bool EditPriceCondition()
	{
		bool result = false;
		if (this.m_UserID == this.m_SalerID)
		{
			if (this.m_productType != "5")
			{
				if (this.IntPayStatus == 0 && this.m_orderStatus == "0")
				{
					result = true;
				}
			}
		}
		return result;
	}
}
